package com.shg.web.mail.action;


import javax.annotation.Resource;

import org.springframework.mail.MailException;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;

public abstract class MailAction {
    @Resource
    private JavaMailSenderImpl mailSender;
    
    private SimpleMailMessage simpleMailMessage;
    
    /**
     * 获取验证吗
     * @return
     */
    protected abstract String validate();
    /**
     * 更加用户发送过来的数据发送邮件
     * @param to		邮箱接收者
     * @param title		邮箱的标题
     * @param content	邮箱主要内容
     */
    public final void sendMail(String to,String title,String content){
    	try {
			if(simpleMailMessage==null)
				simpleMailMessage=new SimpleMailMessage();
			
			simpleMailMessage.setTo(to);
			simpleMailMessage.setSubject(title);
			simpleMailMessage.setText(content);
			//发送者
			simpleMailMessage.setFrom(mailSender.getUsername());
			//发送电子邮件
			mailSender.send(simpleMailMessage);
		} catch (MailException e) {
			e.printStackTrace();
		}
    }
    
}
